package game.bejeweled
{
	import flash.geom.Point;
	
	import models.ProfileModel;

	public class TestSameBall
	{
		public function TestSameBall()
		{
		}
		
		public static function sameBallVec():Vector.<Point>{
			var returnVec:Vector.<Point>=new Vector.<Point>();
			returnVec=cloneBall(returnVec,sameRowNumVec());
			returnVec=cloneBall(returnVec,sameColumnNumVec());
			returnVec=cloneBall(returnVec,sameBeveledVec());
			returnVec=cloneBall(returnVec,sameBeveledLeftVec());
//			trace(sameColumnNumVec())
//			trace("-------------------")
//			trace(sameColumnNumVec2())
			return returnVec;
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */	
		public static function sameRowNumVec():Vector.<Point>{
			var returnVec:Vector.<Point>=new Vector.<Point>();
			var tempVec:Vector.<Point>=new Vector.<Point>();
			for (var i:int = 0; i < ProfileModel.instant.row; i++) 
			{
				var stepNum:int=0;
				tempVec.push(new Point(i,stepNum));
				while(stepNum<ProfileModel.instant.column-1){
					if(ProfileModel.instant.backdropVec[i][stepNum].currBall.sign==ProfileModel.instant.backdropVec[i][++stepNum].currBall.sign){
						var bd:Point=new Point(i,stepNum);
						tempVec.push(bd);
					}else{
						if(tempVec.length>=ProfileModel.instant.EvenSum){
							returnVec=cloneBall(returnVec,tempVec);
						}
						tempVec=new Vector.<Point>();
						tempVec.push(new Point(i,stepNum));
					}
				}
				if(tempVec.length>=ProfileModel.instant.EvenSum){
					returnVec=cloneBall(returnVec,tempVec);
				}
				tempVec=new Vector.<Point>();
			}
			return returnVec
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */		
		public static function sameColumnNumVec():Vector.<Point>{
			var returnVec:Vector.<Point>=new Vector.<Point>();
			var tempVec:Vector.<Point>=new Vector.<Point>();
			for (var i:int = 0; i < ProfileModel.instant.column; i++) 
			{
				var stepNum:int=0;
				tempVec.push(new Point(stepNum,i));
				while(stepNum<ProfileModel.instant.row-1){
					if(ProfileModel.instant.backdropVec[stepNum][i].currBall.sign==ProfileModel.instant.backdropVec[++stepNum][i].currBall.sign){
						var bd:Point=new Point(stepNum,i);
						tempVec.push(bd);
					}else{
						if(tempVec.length>=ProfileModel.instant.EvenSum){
							returnVec=cloneBall(returnVec,tempVec);
						}
						tempVec=new Vector.<Point>();
						tempVec.push(new Point(stepNum,i));
					}
				}
				if(tempVec.length>=ProfileModel.instant.EvenSum){
					returnVec=cloneBall(returnVec,tempVec);
				}
				tempVec=new Vector.<Point>();
			}
			
			return returnVec;
		}
		
		
		public static function sameColumnNumVec2():Vector.<Point>{
			var returnVec:Vector.<Point>=new Vector.<Point>();
			var tempVec:Vector.<Point>=new Vector.<Point>();
			for (var i:int = 0; i < ProfileModel.instant.column; i++) 
			{
				var stepNum:int=0;
				tempVec.push(new Point(stepNum,i));
				while(stepNum<ProfileModel.instant.row-1){
					var nextStep:int=stepNum+1;
					if(ProfileModel.instant.backdropVec[stepNum][i].currBall.sign==ProfileModel.instant.backdropVec[nextStep][i].currBall.sign){
					}else{
						if(tempVec.length>=ProfileModel.instant.EvenSum){
							returnVec=cloneBall(returnVec,tempVec);
						}
						tempVec=new Vector.<Point>();
					}
					var bd:Point=new Point(nextStep,i);
					tempVec.push(bd);
					stepNum=nextStep
				}
				if(tempVec.length>=ProfileModel.instant.EvenSum){
					returnVec=cloneBall(returnVec,tempVec);
				}
				tempVec=new Vector.<Point>();
			}
			
			return returnVec;
		}
		
		/**
		 * 
		 * 
		 */
		
		public static function sameBeveledVec():Vector.<Point>{
			var returnVec:Vector.<Point>=new Vector.<Point>();
			var tempVec:Vector.<Point>=new Vector.<Point>();
			var rowL:int=ProfileModel.instant.row;
			var columnL:int=ProfileModel.instant.column;
			var currBdVec:Vector.<Vector.<BackDrop>>=ProfileModel.instant.backdropVec
			var iLength:int=rowL+columnL-1;
			
			var beginNo:int=ProfileModel.instant.EvenSum-1;
			var endNo:int=iLength-beginNo;
			
			var rStep:int=0;
			var cStep:int=beginNo;
			
			var i:int=beginNo
			for (; i < endNo; i++){
				if(i<columnL){
					rStep=0;
					cStep=i;
				}else{
					rStep=i-columnL+1;
					cStep=columnL-1;
					
				}
				var nextrStep:int=rStep+1;
				var nextcStep:int=cStep-1;	
				
				tempVec.push(new Point(rStep,cStep));
				
				while(0<= nextrStep && nextrStep<rowL && 0<= nextcStep && nextcStep < columnL){
					
					if(currBdVec[rStep][cStep].currBall.sign==currBdVec[nextrStep][nextcStep].currBall.sign){
						var bd:Point=new Point(nextrStep,nextcStep);
						tempVec.push(bd);
					}else{
						if(tempVec.length>=ProfileModel.instant.EvenSum){
//							returnVec.push(cloneBall(tempVec));
							returnVec=cloneBall(returnVec,tempVec);
						}
						tempVec=new Vector.<Point>();
						tempVec.push(new Point(nextrStep,nextcStep));
					}
					rStep=nextrStep;
					cStep=nextcStep;
					nextrStep=rStep+1;
					nextcStep=cStep-1;				
				}
				
				if(tempVec.length>=ProfileModel.instant.EvenSum){
//					returnVec.concat(cloneBall(tempVec));
					returnVec=cloneBall(returnVec,tempVec);
				}
				tempVec=new Vector.<Point>();
			}
			
			return returnVec;
		}
		public static function sameBeveledLeftVec():Vector.<Point>{
			var returnVec:Vector.<Point>=new Vector.<Point>();
			var tempVec:Vector.<Point>=new Vector.<Point>();
			var rowL:int=ProfileModel.instant.row;
			var columnL:int=ProfileModel.instant.column;
			var evenSum:int=ProfileModel.instant.EvenSum;
			var currBdVec:Vector.<Vector.<BackDrop>>=ProfileModel.instant.backdropVec
			var iLength:int=rowL+columnL-1;
			
			var beginNo:int=rowL-evenSum;
			
			var endNo:int=beginNo+columnL-evenSum+1;
			
			var rStep:int=beginNo+1;
			var cStep:int=0;
			
			var step:int=beginNo;
			
			var isboolean:Boolean=true;
			for (var i:int=0; i <endNo; i++) 
			{
				
				if(isboolean){
					rStep=step;
					cStep=0;	
					step--
				}else{
					rStep=0;
					cStep=step;	
					step++
				}
				
				if(step<=0){
					isboolean=!isboolean;
				}
				
				var nextrStep:int=rStep+1;
				var nextcStep:int=cStep+1;	
				
				tempVec.push(new Point(rStep,cStep));
				
				while(0<= nextrStep && nextrStep<rowL && 0<= nextcStep && nextcStep < columnL){
					
					if(currBdVec[rStep][cStep].currBall.sign==currBdVec[nextrStep][nextcStep].currBall.sign){
						var bd:Point=new Point(nextrStep,nextcStep);
						tempVec.push(bd);
					}else{
						if(tempVec.length>=ProfileModel.instant.EvenSum){
//							returnVec.push(cloneBall(tempVec));
							returnVec=cloneBall(returnVec,tempVec);
						}
						tempVec=new Vector.<Point>();
						tempVec.push(new Point(nextrStep,nextcStep));
					}
					rStep=nextrStep;
					cStep=nextcStep;
					nextrStep=rStep+1;
					nextcStep=cStep+1;				
				}
				
				if(tempVec.length>=ProfileModel.instant.EvenSum){
//					returnVec.concat(cloneBall(tempVec));
					returnVec=cloneBall(returnVec,tempVec);
				}
				tempVec=new Vector.<Point>();
			}
			
			return returnVec;
		}
		
		
//		private static function cloneBall2(tempVec:Vector.<Point>):Vector.<Point>{
//			var newVec:Vector.<Point>=new Vector.<Point>();
//			for (var j:int = 0; j < tempVec.length; j++) 
//			{
//				var newbdn:Point=new Point(tempVec[j].x,tempVec[j].y);
//				newVec.push(newbdn);
//			}
//			return newVec;
//		}
		
		private static function cloneBall(returnVec:Vector.<Point>,tempVec:Vector.<Point>):Vector.<Point>{
			for (var j:int = 0; j < tempVec.length; j++) 
			{
				var newbdn:Point=new Point(tempVec[j].x,tempVec[j].y);
				returnVec.push(newbdn);
			}
			return returnVec;
		}
	}
}

